package com.ydm.myapp001.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.ydm.myapp001.R;
import com.ydm.myapp001.adapter.GoodsCategoryAdapter;
import com.ydm.myapp001.adapter.RecycleViewFenZuAdapter;
import com.ydm.myapp001.bean.OneGoodsCategory;
import com.ydm.myapp001.bean.OneGroupBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class FenZuRecylceViewActivity extends AppCompatActivity {
    @BindView(R.id.rv_fenzu)
    RecyclerView rvFenzu;

    private final String TAG = this.getClass().getSimpleName();
    private Context mContext;
    private RecycleViewFenZuAdapter rvFenZuAdapter;
    private ArrayList<OneGroupBean> list; //list为二维数组

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fen_zu_recylce_view);

        //1.
        // 初始化View注入
        ButterKnife.bind(this);
        mContext = this;

        //2.数据源赋值
        list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            OneGroupBean oneGroupBean = new OneGroupBean();
            ArrayList<String> lis = new ArrayList<>();
            for (int j = 0; j < i; j++) {
                lis.add(i + "=" + j);
            }
            oneGroupBean.setDataList(lis);
            oneGroupBean.setGroupTitle("第" + i + "组");
            list.add(oneGroupBean);
        }

        //3.RecycleView
        rvFenZuAdapter = new RecycleViewFenZuAdapter(mContext, list);
        rvFenzu.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        //rvFenzu.addItemDecoration(new MyItemDecoration(1)); //自己指定item间距 (如果不指定就没有间隔)
        rvFenzu.setAdapter(rvFenZuAdapter);
    }



    public class MyItemDecoration extends RecyclerView.ItemDecoration {
        private int bottomGap;

        public MyItemDecoration(int bottomGap) {
            this.bottomGap = bottomGap;
        }

        /**
         * @param outRect 边界
         * @param view    recyclerView ItemView
         * @param parent  recyclerView
         * @param state   recycler 内部数据管理
         */
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            //设定底部边距
            outRect.set(0, 0, 0, bottomGap); //outRect中的left top right bottom是px值
        }
    }

}
